package Sudoku3.structure;
import java.util.ArrayList;
import java.util.BitSet;


public abstract class group extends ArrayList<cell> {

	private static final long serialVersionUID = 1L;
	
	protected int _id;
	
	public int getID() { return _id; }
	
	//a bitmask representing which cells in the group have value (v) as a possiblity
	public BitSet getPossible(int v) {
		BitSet b = new BitSet(this.size());
		for (int i = 0; i < 9; i++) {
			b.set(i, this.get(i).isPossible(v));
		}
		return b;
	}
	
    public bucket getCellSet() {
        //return (bucket) this.clone();
    	bucket b = new bucket();
    	for (cell c : this) { b.add(c); }
    	return b;
    }
	
	//cells that are common to this group and another group
	public bucket getCommonCells(group g) {
		bucket b = this.getCellSet();
		b.retainAll(g.getCellSet());
		return b;
	}
	
	//test if this group intersects another group
	public boolean intersects(group g) { return !getCommonCells(g).isEmpty(); }
	
	public int getSolvedCellCount() {
		int count = 0;
		for (cell c : this) { if (c.isSolved()) { count++; } }
		return count;
	}
	
	public int getUnSolvedCellCount() {
		int count = 0;
		for (cell c : this) { if (!(c.isSolved())) { count++; } }
		return count;
	}
	
	public String toString() {
		String r = "";
		
		if (this instanceof row) { r = "R" + _id; }
		else if (this instanceof col) { r = "C" + _id; }
		else if (this instanceof blk) { r = "B" + _id; }
		else r = "bucket";
		return r;
	}
	
	public String toStringCells() {
		String s = "";
		for (cell c : this) { s += c.toStringCoords() + ",";}
		s = s.substring(0, s.length() - 1);
		return s;
	}
	
	
	
	
	
}